resolve main class automatically#71
Conversation
Signed-off-by: xuzho <xuzho@microsoft.com>
| List<String> projectNames; | ||
| if (arguments.size() > 1 && arguments.get(1) != null) { | ||
| // project name specified | ||
| projectNames = new ArrayList<String>(); |
| projects.add(rootElm.elementText("name")); | ||
| } catch (DocumentException e) { | ||
| // TODO Auto-generated catch block | ||
| e.printStackTrace(); |
There was a problem hiding this comment.
i don't see any close/dispose method for Reader/document
| e.printStackTrace(); | ||
| } | ||
| } | ||
| projects.add(null); |
There was a problem hiding this comment.
fall back to workspace scope
| IJavaSearchScope searchScope = createSearchScope(projectName); | ||
| SearchPattern pattern = SearchPattern.createPattern("main(String[]) void", IJavaSearchConstants.METHOD, | ||
| IJavaSearchConstants.DECLARATIONS, SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_EXACT_MATCH); | ||
| ArrayList<String> uris = new ArrayList<String>(); |
There was a problem hiding this comment.
List<String> uris = new ArrayList<>()
Signed-off-by: xuzho <xuzho@microsoft.com>
| private List<String> resolveProjectName(List<String> projectFiles) { | ||
| List<String> projects = new ArrayList<>(); | ||
| for (String f : projectFiles) { | ||
| SAXReader reader = new SAXReader(); |
There was a problem hiding this comment.
Does eclipse have any built-in utility to help parse .project file?
| SearchEngine searchEngine = new SearchEngine(); | ||
| searchEngine.search(pattern, new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, | ||
| searchScope, requestor, null /* progress monitor */); | ||
| return uris.size() == 0 ? null : uris.get(0); |
There was a problem hiding this comment.
if there are multiple main class in the target project, should pop up a dropdown menu in UI to tell user to choose one.[#Pending]
There was a problem hiding this comment.
I think we should return multiple to let js side has the possibilities to choose.
Signed-off-by: xuzho <xuzho@microsoft.com>
| } | ||
| if (o instanceof ResolutionItem) { | ||
| ResolutionItem item = (ResolutionItem) o; | ||
| return item.mainClass == this.mainClass && item.projectName == this.projectName; |
There was a problem hiding this comment.
in java == is not for equal test.
There was a problem hiding this comment.
nice catch, i should use equals instead
| if (project != null) { | ||
| String mainClass = method.getDeclaringType().getFullyQualifiedName(); | ||
| String projectName = ProjectsManager.DEFAULT_PROJECT_NAME.equals(project.getName()) ? null : project.getName(); | ||
| uris.add(new ResolutionItem(mainClass, projectName)); |
| * @return main class and project name | ||
| * resolve main class and project name. | ||
| * @return an array of main class and project name | ||
| * @throws CoreException when there are error when resolving main class. |
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return mainClass.hashCode() * 13 + (projectName == null ? 0 : projectName.hashCode()); |
There was a problem hiding this comment.
missing the handle case for null mainClass and null projectName
| IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope(); | ||
| SearchPattern pattern = SearchPattern.createPattern("main(String[]) void", IJavaSearchConstants.METHOD, | ||
| IJavaSearchConstants.DECLARATIONS, SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_EXACT_MATCH); | ||
| ArrayList<ResolutionItem> uris = new ArrayList<>(); |
Signed-off-by: xuzho <xuzho@microsoft.com>
Signed-off-by: xuzho <xuzho@microsoft.com>
| return resolveMainClassCore(); | ||
| } | ||
|
|
||
| private List<ResolutionItem> resolveMainClassCore() throws CoreException { |
There was a problem hiding this comment.
new method resolveMainClassCore is unnecessary.[pending]
Signed-off-by: xuzho xuzho@microsoft.com
microsoft/vscode-java-debug#9